/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf.beans.admin;

import JDBCUtil.MyConn;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import manager.ProManager;
import model.admin.Professional;

/**
 *
 * @author Danh
 */
@ManagedBean
@RequestScoped
public class ProfessionalBean {

    public ProfessionalBean() {
    }
    private int proId;
    private boolean proStatus;
    private String proName;

    public int getProId() {
        return proId;
    }

    public void setProId(int proId) {
        this.proId = proId;
    }

    public boolean isProStatus() {
        return proStatus;
    }

    public void setProStatus(boolean proStatus) {
        this.proStatus = proStatus;
    }

    public String getProName() {
        return proName;
    }

    public void setProName(String proName) {
        this.proName = proName;
    }

    public void reset() {
        
        this.proStatus = false;
        this.proName = null;
    }

    public List<Professional> loadProfessional() {
        List<Professional> list;
        ProManager mana = new ProManager();
        list = mana.getall();
        return list;
    }

    public String editAction(int id, String name, boolean status) {
        this.proId = id;
        this.proName = name;
        this.proStatus = status;
        return "updaProfessional.xhtml";
    }

//    public String saveAction() {
//        //get all existing value but set "editable" to false
//        List<Professional> list = loadProfessional();
//
//        for (Professional pr : list) {
//            ProManager mana = new ProManager();
//            mana.updateProfessional(pr);
//            pr.setEditable(false);
//        }
//        return null;
//    }
    public String insertProfessional() {
        Professional pro = new Professional(proName, proStatus);
        ProManager mana = new ProManager();
        boolean flag = mana.insertProfesional(pro);
        if (flag) {
            loadProfessional();
            return "professional.xhtml?faces-redirect=true";
        }
        return "";
    }

    public String sua() {
        Professional pr = new Professional(proId, proName, proStatus);
        ProManager mana = new ProManager();
        boolean result = mana.updateProfessional(pr);
       
        return "professional.xhtml?faces-redirect=true";
       
    }

    public void deleteProfessional(int id) {

        ProManager mana = new ProManager();
        mana.deleteProfessional(id);
        loadProfessional();
    }

}
